import {LoadingStatus, updateAppState} from '../reducers/app-state';
import HttpClient from '../commons/http-client';
import {updateHistoryVendor} from '../reducers/history-vendor';

export function loadHistory() {
  return async dispatch => {
    dispatch(updateAppState({loading: LoadingStatus.PENDING}));
    try {
      const rep = await HttpClient.get(
        '/web/dentist/history_vendors?no_page=no_page',
      );
      dispatch(updateHistoryVendor(rep.data.data));
      dispatch(updateAppState({loading: LoadingStatus.DONE}));
    } catch (e) {
      dispatch(updateAppState({loading: LoadingStatus.ERROR}));
    }
  };
}
